package com.ktjy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktjy.entity.SysUser;
import com.ktjy.mapper.SysUserMapper;
import com.ktjy.service.ISysUserService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {


    @Cacheable(value = "userList",keyGenerator = "keyGenerator")
    @Override
    public IPage<SysUser> page(IPage<SysUser> page, SysUser user) throws InterruptedException {

//        IPage<SysUser> page = new Page<>(pageIndex, pageSize);
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        if (user != null) {
            queryWrapper.like(StringUtils.hasText(user.getUsrName()), SysUser::getUsrName, user.getUsrName());
            queryWrapper.eq(user.getUsrRoleId() != null, SysUser::getUsrRoleId, user.getUsrRoleId());
        }
        //模拟请求数据时间
        Thread.sleep(2000);
        return baseMapper.selectPage(page, queryWrapper);
    }





}
